% 主程序
x = linspace(-1, 1, 100);  % 定义 x 的范围
x1 = linspace(-1, 1, 10000);
u_test = arrayfun(@u0, x1); % 对 x 的每个元素逐点调用 u0

% 绘图
figure
hold on
plot(x1, u_test(:), 'k-'); % 绘制 u_test 的图像
%plot(x,temp(:,3),'r--','LineWidth',2);
plot(x,uhG(:,3),'b-*');
xlim([-1 1]);  % x 轴范围
ylim([-0.1 1.3]);  % y 轴范围
legend('解析解','MR-Kxrcf ','MR-TVD');  % 图例
grid on
hold off

% 定义 u0(x) 函数
function u = u0(x)
    a = 0.5;
    z = -0.7;
    delta = 0.005;
    phi = 10;
    psi = log(2) / (36 * delta^2);

    % 定义 G(x) 和 F(x)
    G = @(x, psi, z) exp(-psi * (x - z).^2);
    F = @(x, phi, a) sqrt(max(1 - phi^2 * (x - a).^2, 0));

    % 分段定义 u
    if x >= -0.8 && x <= -0.6
        u = (1/6) * (G(x, psi, z - delta) + G(x, psi, z + delta) + 4 * G(x, psi, z));
    elseif x >= -0.4 && x <= -0.2
        u = 1;
    elseif x >= 0 && x <= 0.2
        u = 1 - abs(10 * (x - 0.1));
    elseif x >= 0.4 && x <= 0.6
        u = (1/6) * (F(x, phi, a - delta) + F(x, phi, a + delta) + 4 * F(x, phi, a));
    else
        u = 0;
    end
end

